﻿using In66.Net.Repository.EFCoreData;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Ord.Api.Models.EntityConfig
{
    public class OrderItemConfig : AbstractEntityTypeConfiguration<Aggregates.OrderAggregate.OrderItem>
    {
        public override void Configure(EntityTypeBuilder<Aggregates.OrderAggregate.OrderItem> builder)
        {
            base.Configure(builder);

            builder.Property(x => x.OrderId).IsRequired();

            builder.OwnsOne(x => x.Product, y =>
            {
                y.Property(z => z.Id).IsRequired().HasColumnName("producid");
                y.Property(z => z.Name).IsRequired().HasMaxLength(64).HasColumnName("productname");
                y.Property(z => z.Price).IsRequired().HasColumnName("productprice").HasColumnType("decimal(18,4)");
            });

            builder.Property(x => x.Count).IsRequired();
        }
    }
}
